// 这个promise.race好像是返回最快的promise的值，可以用来搞超时操作
export function query(url: string, delay = 2000) {
  const promises = [
    '',
    new Promise((_, reject) => {
      setTimeout(() => {
        reject('请求超时');
      }, delay);
    }),
  ];
  Promise.race(promises).catch((reason) => console.log(reason));
}

const promises = ['ss', 'sss', 'ssss'].map((s) => {
  return new Promise((resolve, reject) => {
    if (s.length == 3) {
      setTimeout(() => {
        reject('请求超时');
      }, 2000);
    }
    setTimeout(() => {
      resolve('Hello');
    }, s.length * 1500);
  });
});
Promise.race(promises)
  .then((values) => {
    console.log(values);
  })
  .catch((reason) => {
    console.log(reason);
  });
